Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: wrap to_dict() tracebacks for more user-friendly errors #555

Merged
merged 2 commits into from
Mar 5, 2018

Conversation

jakevdp
Copy link
Collaborator

@jakevdp jakevdp commented Mar 5, 2018

This does two things:

  • adds a custom exception that wraps jsonschema.ValidationError and provides tracebacks that are more useful for Altair specifications

  • adds a validate='deep' option that triggers any time there is a validation error on a top-level object.

The result is friendlier tracebacks; for example (compare to #480):

import altair as alt
alt.Chart()

---------------------------------------------------------------------------
SchemaValidationError                     Traceback (most recent call last)
~/anaconda/envs/vega3/lib/python3.6/site-packages/IPython/core/formatters.py in __call__(self, obj, include, exclude)
    968 
    969             if method is not None:
--> 970                 return method(include=include, exclude=exclude)
    971             return None
    972         else:

~/github/altair-viz/altair/altair/vegalite/v2/api.py in _repr_mimebundle_(self, include, exclude)
    239     def _repr_mimebundle_(self, include, exclude):
    240         """Return a MIME bundle for display in Jupyter frontends."""
--> 241         return renderers.get()(self.to_dict())
    242 
    243     def repeat(self, row=Undefined, column=Undefined, **kwargs):

~/github/altair-viz/altair/altair/vegalite/v2/api.py in to_dict(self, *args, **kwargs)
    212         if dct is None:
    213             kwargs['validate'] = 'deep'
--> 214             dct = super(TopLevelMixin, copy).to_dict(*args, **kwargs)
    215 
    216         if is_top_level:

~/github/altair-viz/altair/altair/utils/schemapi.py in to_dict(self, validate, ignore, context)
    225                 self.validate(result)
    226             except jsonschema.ValidationError as err:
--> 227                 raise SchemaValidationError(self, err)
    228         return result
    229 

SchemaValidationError: Invalid specification

        altair.vegalite.v2.api.Chart, validating 'required'

        'mark' is a required property

@jakevdp
Copy link
Collaborator Author

jakevdp commented Mar 5, 2018

Tests pass, I'm going to merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant